from django.db import models

class FundName(models.Model):
    code = models.CharField(verbose_name="基金编码", max_length=20, null=False, primary_key=True)
    name = models.CharField(verbose_name="基金名称", max_length=20, null=False, default="")
    company = models.CharField(verbose_name="基金公司", max_length=20, null=False, default="")
    type = models.CharField(verbose_name="基金类型", max_length=5, null=False, default="")
    risk = models.CharField(verbose_name="基金风险", max_length=10, null=False, default="")
    selfType = models.IntegerField(verbose_name="自定义1", default=0)
    purchaseRate = models.FloatField(verbose_name="基金购买费率", default=0.0)
    sellingRate = models.FloatField(verbose_name="基金出售费率", default=0.0)

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        return

    def __str__(self):
        return str(self.code) + " " + self.name

    class Meta:
        verbose_name = "基金基本信息"
        verbose_name_plural = verbose_name

class CustomCategoryName(models.Model):
    name = models.CharField(verbose_name="自定义分类", max_length=20, null=False)
    priority = models.IntegerField(verbose_name="显示优先级", default=0)

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        return

    class Meta:
        verbose_name = "自定义分类名称管理"
        verbose_name_plural = verbose_name

class CustomCategory(models.Model):
    name = models.CharField(verbose_name="自定义分类", max_length=20, null=False)
    fund = models.ForeignKey('FundName', on_delete=models.CASCADE)
    key1 = models.IntegerField(verbose_name="自定义1", default=0)
    key2 = models.IntegerField(verbose_name="自定义2", default=0)
    key3 = models.IntegerField(verbose_name="自定义3", default=0)
    key4 = models.IntegerField(verbose_name="自定义4", default=0)
    key5 = models.IntegerField(verbose_name="自定义5", default=0)
    key6 = models.IntegerField(verbose_name="自定义6", default=0)

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        return

    class Meta:
        verbose_name = "自定义分类"
        verbose_name_plural = verbose_name

class FundInfoBrief(models.Model):
    fund = models.ForeignKey('FundName', on_delete=models.CASCADE)
    incomeDay = models.FloatField(verbose_name="日收益", null=True)
    incomeDayRate = models.FloatField(verbose_name="日收益率", null=True)
    incomeDayDate = models.DateField(verbose_name="日期", null=True)
    totalIncome = models.FloatField(verbose_name="累计收益", null=True)
    curCost = models.FloatField(verbose_name="持有成本", default=0.0)
    curIncome = models.FloatField(verbose_name="持有收益", null=True)
    curIncomeRate = models.FloatField(verbose_name="收益率", null=True)
    curValue = models.FloatField(verbose_name="持有金额", null=True)
    curUnits = models.FloatField(verbose_name="持有份额", null=True)
    maxDrawDown1Y = models.FloatField(verbose_name="1年回撤", null=True)
    maxDrawDown2Y = models.FloatField(verbose_name="2年回撤", null=True)
    maxDrawDown3Y = models.FloatField(verbose_name="3年回撤", null=True)
    maxDrawDown5Y = models.FloatField(verbose_name="5年回撤", null=True)
    incomeRate1M = models.FloatField(verbose_name="1月收益率", null=True)
    incomeRate3M = models.FloatField(verbose_name="3月收益率", null=True)
    incomeRate6M = models.FloatField(verbose_name="6月收益率", null=True)
    incomeRate1Y = models.FloatField(verbose_name="1年收益率", null=True)
    incomeRate2Y = models.FloatField(verbose_name="2年收益率", null=True)
    incomeRate3Y = models.FloatField(verbose_name="3年收益率", null=True)
    incomeRate5Y = models.FloatField(verbose_name="5年收益率", null=True)
    icomeDrawDownRate1Y = models.FloatField(verbose_name="1Y收益回撤比", null=True)
    income1M = models.FloatField(verbose_name="1月收益", null=True)
    income2M = models.FloatField(verbose_name="2月收益", null=True)
    income3M = models.FloatField(verbose_name="3月收益", null=True)
    income4M = models.FloatField(verbose_name="4月收益", null=True)
    income5M = models.FloatField(verbose_name="5月收益", null=True)
    income6M = models.FloatField(verbose_name="6月收益", null=True)
    incomePre1Y = models.FloatField(verbose_name="1年预测收益", null=True)
    incmePreCurY = models.FloatField(verbose_name="本年预测收益", null=True)
    alarm = models.IntegerField(verbose_name="交易告警", null=True)
    alarmText = models.CharField(verbose_name="告警提示文本", max_length=50, null=True)
    priceAvg1M = models.FloatField(verbose_name="月线", null=True)
    priceAvg6M = models.FloatField(verbose_name="半年线", null=True) 
    priceAvg1Y = models.FloatField(verbose_name="年线", null=True) 
    note = models.TextField(verbose_name="备注", null=True)

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        return

    class Meta:
        verbose_name = "基金分析摘要"
        verbose_name_plural = verbose_name


